package com.njupt.twoStage.BinarySearch;

public class RemoveElementDoublePointer {
    /**
     * 双指针法
     *
     * @param nums
     * @param val
     * @return
     */
    public int removeElement(int[] nums, int val) {
        int left = 0;
        int right = 0;
        for (right = 0; right < nums.length; right++) {
            if (nums[right] != val) {
                nums[left] = nums[right];
                left++;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        int[] nums = {0,1,2,2,3,0,4,2};
        RemoveElementDoublePointer test = new RemoveElementDoublePointer();
        int len = test.removeElement(nums, 2);
        System.out.println(len);
    }
}
